<?php




if(Antz_IntelliForm::submitted('new_notification')){
    $error = false;
    
    $subid = (int) post('subscription_id');
    $numDays = (int) post('numDays');
    $subject = post('subject');
    $content = post('content');
    
    if($DB->countRows(cms_db_prefix().'isubscribe_subscriptions', "id = '{$subid}'")==0){
      $error = true;
      Antz::addFormError('subscription_id');
    }
    
    if($numDays < 0){
        $error = true;
        Antz::addFormError('numDays');
    }
    
    if(trim($subject)==''){
        $error = true;
        Antz::addFormError('subject');
    }
    
    if(trim($content)==''){
        $error = true;
        Antz::addFormError('content');
        Antz::addError($this->Lang('content_is_blank'));
    }
    
    if(!$error){
        $dbParams = array(
            'subscription_id' => $subid,
            'num_days' => $numDays,
            'subject' => $subject,
            'content' => $content
        );
        $notid = $DB->insert(cms_db_prefix().'isubscribe_notifications', $dbParams);
        Antz::addSuccess($this->Lang('notification_set'));
        Antz::redir($Antz->addParamsToUrl($actionUrls['edit_notification'], array('notid'=>$notid)));
    }

}























$subOpts = array();
$subs = $DB->fetchAll("SELECT * FROM {$this->config['db_prefix']}isubscribe_subscriptions ORDER BY is_deleted, is_active, title");
foreach($subs as $k=>$v){
    $subOpts[$v['id']] = $v['title'].' ['.$v['keyname'].']';
};

$formFields = array(
    array(
        'name' => 'subscription_id',
        'type' => 'select',
        'value' => post('subscription_id'),
        'label' => $this->Lang('subscription'),
        'options' => $subOpts
    ),
    array(
        'name' => 'subject',
        'type' => 'text',
        'value' => post('subject'),
        'label' => $this->Lang('subject'),
        'class' => 'wide'
    ),
    array(
        'name' => 'content',
        'type' => 'tinymce',
        'value' => post('content'),
        'label' => $this->Lang('content'),
        'id' => 'IS_new-notification'
    ),
    array(
        'name' => 'numDays',
        'type' => 'text',
        'value' => post('numDays'),
        'label' => $this->Lang('days_prior'),
        'class' => 'short'
    )
);

$form = Antz::makeRapidForm($formFields, $this->Lang('new_notification_legend'), 'new_notification');

$form->addSubmit($this->Lang('submit'));

echo '<h2 class="accessibility">'.$this->Lang('new_notification').'</h2>';

echo $form->render();




